﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

namespace ProjectSell
{
    public class DataObject
    {
        private SeriCard seriCard;
        private clsDatabase clsData;
  
        public string Error { get; set; }


        public DataObject()
        {
            try
            {
                
                seriCard = new SeriCard();
                clsData = new clsDatabase();
            }
            catch (Exception ex)
            {
                Error = ex.Message;
                Console.WriteLine("Data Object:" + ex.Message);
            }
        }



        public int AddSeriCard(SeriCard seriCard)
        {
            try
            {
                string sql = "INSERT INTO SeriCard (LoaiThe,SoSeri,MaVcion,TaiKhoan) VALUES ('" + seriCard.LoaiThe + "','" + seriCard.SoSeri + "','" + seriCard.MaVcoin + "','" + seriCard.TaiKhoan + "')";
                return clsData.Execute(sql);
            }
            catch (Exception ex)
            {
                Error = ex.Message;
                Console.WriteLine("Add sericard: " + ex.Message);
                return -1;
            }            
        }


        public int DeleteSeriCardByUserName(string userName)
        {
            try
            {
                return clsData.Execute("DELETE SeriCard WHERE TaiKhoan = '" + userName + "'");
            }
            catch (Exception ex)
            {
                Error = ex.Message;
                Console.WriteLine("DeleteSeriCardByUserName:" + ex.Message);
                return -1;
            }
        }

        public int DeleteSericard(SeriCard sericard)
        {
            try
            {
                return clsData.Execute("DELETE FROM  SeriCard WHERE LoaiThe = '" + sericard.LoaiThe + "' AND SoSeri = '" + sericard.SoSeri + "' AND MaVcion = '" + sericard.MaVcoin + "' AND TaiKhoan = '" + sericard.TaiKhoan + "'");

            }
            catch (Exception ex)
            {
               Error = ex.Message;
                Console.WriteLine("Delete Sericard:" + ex.Message);
                return -1;
            }
        }


        public DataTable GetAllSeriCard()
        {
            try
            {
                DataTable dtt = clsData.FillData("SELECT * FROM SeriCard");
                return dtt;
            }
            catch (Exception ex)
            {
                Error = ex.Message;
                Console.WriteLine("Get ALl Sericard:" + ex.Message);
                return null;
            }
        }

        public bool DangNhap(string tenDangNhap, string matKhau)
        {
            try
            {
                int result = clsData.ExecuteReturn("DangNhap", tenDangNhap, matKhau);
                if (result == 1)
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                Error = ex.Message;
                Console.WriteLine("Dang Nhap:" + ex.Message);
                return false;
            }
            return false;
        }

    }
}